/**
 * @file
 * @brief 中断向量表
 * @author
 * + 隐星魂 (Roy Sun) <xwos@xwos.tech>
 * @copyright
 * + Copyright © 2015 xwos.tech, All Rights Reserved.
 * > Licensed under the Apache License, Version 2.0 (the "License");
 * > you may not use this file except in compliance with the License.
 * > You may obtain a copy of the License at
 * >
 * >         http://www.apache.org/licenses/LICENSE-2.0
 * >
 * > Unless required by applicable law or agreed to in writing, software
 * > distributed under the License is distributed on an "AS IS" BASIS,
 * > WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * > See the License for the specific language governing permissions and
 * > limitations under the License.
 */

#include <xwos/standard.h>
#include <xwos/ospl/irq.h>
#include <xwos/ospl/syshwt.h>
#include <xwos/ospl/skd.h>

extern xwu8_t armv7m_isr_stack_top[];

struct soc_ivt {
        xwisr_f exc[SOCCFG_EXC_NUM];
        xwisr_f irq[SOCCFG_IRQ_NUM];
};

extern void reset_handler(void);
extern void nmi_handler(void);
extern void svc_handler(void);

__xwcc_section(".armv7m.ivt") struct soc_ivt s32k1_ivt = {
        .exc = {
                [SOC_SP_TOP + (int)SOCCFG_EXC_NUM] = (xwisr_f)armv7m_isr_stack_top,
                [SOC_EXC_RESET + (int)SOCCFG_EXC_NUM] = reset_handler,
                [SOC_EXC_NMI + (int)SOCCFG_EXC_NUM] = nmi_handler,
                [SOC_EXC_HARDFAULT + (int)SOCCFG_EXC_NUM] = arch_isr_hardfault,
                [SOC_EXC_MMFAULT + (int)SOCCFG_EXC_NUM] = arch_isr_mm,
                [SOC_EXC_BUSFAULT + (int)SOCCFG_EXC_NUM] = arch_isr_busfault,
                [SOC_EXC_USGFAULT + (int)SOCCFG_EXC_NUM] = arch_isr_usagefault,
                [SOC_EXC_RSVN9 + (int)SOCCFG_EXC_NUM] = arch_isr_noop,
                [SOC_EXC_RSVN8 + (int)SOCCFG_EXC_NUM] = arch_isr_noop,
                [SOC_EXC_RSVN7 + (int)SOCCFG_EXC_NUM] = arch_isr_noop,
                [SOC_EXC_RSVN6 + (int)SOCCFG_EXC_NUM] = arch_isr_noop,
                [SOC_EXC_SVCALL + (int)SOCCFG_EXC_NUM] = svc_handler,
                [SOC_EXC_DBGMON + (int)SOCCFG_EXC_NUM] = arch_isr_dbgmon,
                [SOC_EXC_RSVN3 + (int)SOCCFG_EXC_NUM] = arch_isr_noop,
                [SOC_EXC_PENDSV + (int)SOCCFG_EXC_NUM] = xwospl_skd_isr_swcx,
                [SOC_EXC_SYSTICK + (int)SOCCFG_EXC_NUM] = xwospl_syshwt_isr,
        },
        .irq = {
                [0 ... (SOCCFG_IRQ_NUM - 1)] = arch_isr_noop,
        },
};
